package com.xyongfeng.foodManagement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyongfeng.foodManagement.constant.CaffeineKey;
import com.xyongfeng.foodManagement.domain.FoodCategoryInfo;
import com.xyongfeng.foodManagement.domain.FoodInfo;
import com.xyongfeng.foodManagement.mapper.FoodInfoMapper;
import com.xyongfeng.foodManagement.service.FoodCategoryInfoService;
import com.xyongfeng.foodManagement.service.FoodInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xyongfeng
 * @description 针对表【food_info】的数据库操作Service实现
 * @createDate 2023-12-17 17:02:37
 */
@Service
public class FoodInfoServiceImpl extends ServiceImpl<FoodInfoMapper, FoodInfo>
        implements FoodInfoService {

    @Autowired
    private FoodCategoryInfoService foodCategoryInfoService;
    @Autowired
    private FoodInfoMapper foodInfoMapper;


    @Override
    public List<FoodInfo> selectAll() {
        List<FoodInfo> list = list();
        // 绑定食品种类
        list = list.stream().peek((x) -> {
            FoodCategoryInfo foodCategoryInfos =
                    foodCategoryInfoService.getOne(new QueryWrapper<FoodCategoryInfo>()
                            .eq("category_id", x.getFoodCategoryId()));
            x.setFoodCategoryInfo(foodCategoryInfos);
        }).collect(Collectors.toList());
        return list;
    }

    @Override
    public List<FoodInfo> takeQueryFoodNumLt(Integer stock) {

        return foodInfoMapper.takeQueryFoodNumLt(stock);
    }
}




